@extends('Home/Layout/base_login_resgister')

@section('title', '忘记密码页面')

@section('css')

    <style>
    .codeimg{
        position: absolute; top: 0; right: 0; width: 126px; height: 52px; line-height: 52px; text-align: center; 
    }        

    </style>
@endsection

@section('main')
    <div class="main-wrap">
        <div class="wrapper">
            <div class="center-box ">

                <div class="box-hd box-hd-tabs">
                    <a href="javascript:;" class="item">手机重置密码</a>
                    <a href="javascript:;" class="item">邮箱重置密码</a>
                </div>
                <div class="tab-con">

                        <label class="txtin-box">
                            <input id="checkphone" class="txtin" type="text" name="phone" placeholder="手机" />
                        </label>
                        <label class="txtin-box txtin-box-code">
                            <input id='phonecode' class="txtin" type="text" name="phonecode" placeholder="短信验证码" />

                            <input id='getphonecode' class="get-yzm" type='button' value="获取验证码">
                        </label>
                        <label class="txtin-box txtin-box-code">
                            <input id='code' class="txtin" type="text" name="code" placeholder="验证码" />

                            <img class="codeimg" src="{{url('/makecode')}}" onclick="this.src='{{url('/makecode')}}?'+Math.random()"  title="看不清楚，再点一次">
                        </label>
                        <input id='phoneRePwd' class="tj" type="button" value="完&ensp;成" />
                       

                </div>
                <div class="tab-con">

                        <label class="txtin-box">
                            <input id='checkemail' class="txtin" type="text" name="email" placeholder="邮箱" />
                        </label>
                       <label class="txtin-box txtin-box-code">
                            <input id='emailcode' class="txtin" type="text" name="emailcode" placeholder="邮箱验证码" />
                            <input id='getemailcode' class="get-yzm" type='button' value="获取验证码">
                        </label>
                         <label class="txtin-box txtin-box-code">
                            <input id='code2' class="txtin" type="text" name="code2" placeholder="验证码" />

                            <img class="codeimg" src="{{url('/makecode')}}" onclick="this.src='{{url('/makecode')}}?'+Math.random()"  title="看不清楚，再点一次">
                        </label>
                        <input id='emailReP' class="tj" type="button" value="完&ensp;成" />

                </div>
            </div>
        </div>
    </div>
@endsection

@section('footer-js')
<script>
     $(function () {
        $('.center-box').zTab({
            tabnav:'.box-hd-tabs',
            trigger:'click'
        });
     });

     //发送手机短信验证码
    wait = 30;
    var InterValObj; //timer变量，控制时间  

    $('#getphonecode').on('click', function(){
        var uphone = $('input[name="phone"]').val();

        $(this).attr('disabled', true).val(wait+'秒后重新发送');
        InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次


        $.axpost(
            'post',
            '{{url("/send")}}',
            'phone='+uphone+'&_token={{csrf_token()}}',
            function (data) { 
                
            }

        );

        //timer处理函数  
        function SetRemainTime() {  
        if (wait < 1) {         
            window.clearInterval(InterValObj);//停止计时器 
            wait = 30;
            $('#getphonecode').attr("disabled", false);//启用按钮  
            $('#getphonecode').val("重新发送验证码");  
        } else {
            wait = wait - 1; 
            $('#getphonecode').val(wait+'秒后重新发送');  
        }
    }
});

    $('#phoneRePwd').on('click', function() {

        var uphone = $('input[name="phone"]').val();
        var uphonecode = $('input[name="phonecode"]').val();
        var ucode = $('input[name="code"]').val();

    $.axpost(
        'post',
        '{{url("/phoneRePwd")}}',
        'phone='+uphone+'&phonecode='+uphonecode+'&_token={{csrf_token()}}'+'&code='+ucode,
        function (data) {

            //验证是否电话不存在错误提示
            if (data.status==1400){

                layer.tips(data.msg, '#checkphone', {tips:[2, '#FF0000']});
            }

            //验证码错误提示
            if (data.status==1401){

                layer.tips(data.msg, '#code', {tips:[4, '#FF0000']});
            }

            //短信验证码错误提示
            if (data.status==1402){

                layer.tips(data.msg, '#phonecode', {tips:[4, '#FF0000']});
            }

            if (data.status==1201){
                $phone = data.msg;

                location.href = '{{url("/doResetPwd/")}}'+"/"+$phone;
            }

        },

        function (tipString) {
            
            if (tipString.responseText) {

                var tipObj = JSON.parse(tipString.responseText).errors;

                if (tipObj['phone']) {
                    layer.tips(tipObj['phone'], '#checkphone', {
                        tips:[2, '#FF0000'],
                        tipsMore: true
                    });
                }

                if (tipObj['phonecode']) {
                    layer.tips(tipObj['phonecode'], '#phonecode', {
                        tips:[4, '#FF0000'],
                        tipsMore: true
                    });
                }

                if (tipObj['code']) {
                    layer.tips(tipObj['code'], '#code', {
                        tips:[4, '#FF0000'],
                        tipsMore: true
                    });
                }
            }
        }

    );
});

   //发送邮箱短信验证码
    $('#getemailcode').on('click', function(){
        var uemail = $('input[name="email"]').val();

        $(this).attr('disabled', true).val(wait+'秒后重新发送');
        InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次


        $.axpost(
            'post',
            '{{url("/sendemail")}}',
            'email='+uemail+'&_token={{csrf_token()}}',
            function (data) {}
        );

        //timer处理函数  
        function SetRemainTime() {  
        if (wait < 1) {         
            window.clearInterval(InterValObj);//停止计时器 
            wait = 30;
            $('#getemailcode').attr("disabled", false);//启用按钮  
            $('#getemailcode').val("重新发送验证码");  
        } else {
            wait = wait - 1; 
            $('#getemailcode').val(wait+'秒后重新发送');  
        }
    }
});

    //邮箱重置密码
    $('#emailReP').on('click', function() {
        var uemail = $('input[name="email"]').val();
        var uemailcode = $('input[name="emailcode"]').val();
        var ucode = $('input[name="code2"]').val();

    $.axpost(
        'post',
        '{{url("/emailRePwd")}}',
        'email='+uemail+'&emailcode='+uemailcode+'&_token={{csrf_token()}}'+'&code='+ucode,
        function (data) {

            //验证是否邮箱不存在错误提示
            if (data.status==1400){

                layer.tips(data.msg, '#checkemail', {tips:[2, '#FF0000']});
            }

            //验证码错误提示
            if (data.status==1401){

                layer.tips(data.msg, '#code2', {tips:[4, '#FF0000']});
            }

            //短信验证码错误提示
            if (data.status==1402){

                layer.tips(data.msg, '#emailcode', {tips:[4, '#FF0000']});
            }

            if (data.status==1200){
                $uemail = data.msg;
            
                location.href = '{{url("/doResetPwd/")}}'+"/"+$uemail;
            }

        },

        function (tipString) {
            
            if (tipString.responseText) {

                var tipObj = JSON.parse(tipString.responseText).errors;

                if (tipObj['email']) {
                    layer.tips(tipObj['email'], '#checkemail', {
                        tips:[2, '#FF0000'],
                        tipsMore: true
                    });
                }

                if (tipObj['emailcode']) {
                    layer.tips(tipObj['emailcode'], '#emailcode', {
                        tips:[4, '#FF0000'],
                        tipsMore: true
                    });
                }

                if (tipObj['code']) {
                    layer.tips(tipObj['code'], '#code2', {
                        tips:[4, '#FF0000'],
                        tipsMore: true
                    });
                }
            }
        }

    );
});
</script>

@endsection
